﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using ManYor.Phone.Common;
using ManYor.Effect;
using Microsoft.Phone.Reactive;

namespace ManYor
{
    public partial class MainPage : PhoneApplicationPage
    {
        public MainPage()
        {
            InitializeComponent();

            // Set the data context of the listbox control to the sample data
            //DataContext = App.ViewModel;
            this.Loaded += new RoutedEventHandler(MainPage_Loaded);
        }
        // Load data for the ViewModel Items
        private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            if (!App.ViewModel.IsDataLoaded)
            {
                App.ViewModel.LoadData();
                App.ViewModel.Items.ToObservable()
                .OnTimeline(TimeSpan.FromSeconds(.25))
                .ObserveOnDispatcher()
                .Subscribe(new Action<ItemViewModel>((o) => CategoryList.Items.Add(o) ));
            }
            if (!App.TaskViewModel.IsDataLoaded)
            {
                App.TaskViewModel.LoadData();
            }
            this.Lb_Task.ItemsSource = App.TaskViewModel.TaskItems;
            //this.Lb_Recent.ItemsSource = App.TaskViewModel.TaskItems;
            this.Lb_Recent.ItemsSource = new List<string> { "Item1", "Item2", "Item3", "Item4", "Item5", "Item3", "Item4", "Item5" };
            //this.Lb_Task.ItemsSource = new List<string> { "task1", "task2", "task3", "task4"};
        }

        private void Lb_Recent_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/SliderShow.xaml", UriKind.Relative));
        }
    }
}